package cn.sf.sufingadminprovider.serviceImpl;

import cn.sf.pojo.User;
import cn.sf.service.AdminService;
import cn.sf.sufingadminprovider.dao.AdminMapper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class AdminServiceImpl implements AdminService {

  @Resource private AdminMapper adminMapper;

  @Override
  @RequestMapping("/selectAdminInfoById")
  public List<User> selectAdminInfoById(@RequestParam("userRole") long userRole) {

    System.out.println("根据userRole查询管理员信息");

    return adminMapper.selectAdminInfoById(userRole);
  }

  @Override
  @RequestMapping("/selectAdminInfoByType")
  public List<User> selectAdminInfoByType(@RequestParam("roleType") long roleType) {
    System.out.println("根据角色类型查询");
    return adminMapper.selectAdminInfoByType(roleType);
  }

  @Override
  @RequestMapping("/selectAdminInfoByEmail")
  public List<User> selectAdminInfoByEmail(@RequestParam("email") String email) {
    System.out.println("邮箱地址查询");
    return adminMapper.selectAdminInfoByEmail(email);
  }

  @Override
  @RequestMapping("/selectAdminInfoByPhone")
  public List<User> selectAdminInfoByPhone(@RequestParam("phone") long phone) {
    System.out.println("手机号查询");
    return adminMapper.selectAdminInfoByPhone(phone);
  }

  @Override
  @RequestMapping("/updateAdminInfoByUserId")
  public int updateAdminInfoByUserId(@RequestBody User user) {

    int result = adminMapper.updateAdminInfoByUserId(user);
    if (result > 0) {
      System.out.println("根据用户id进行管理员信息修改");
      return 1;
    } else {
      return 0;
    }
  }

  @Override
  @RequestMapping("/insertAdminInfo")
  public int insertAdminInfo(@RequestBody User user) {
    int result = adminMapper.insertAdminInfo(user);
    if (result > 0) {
      System.out.println("添加管理员信息");
      return 1;
    } else {
      return 0;
    }
  }

  @Override
  @RequestMapping("/deleteAdminByUserId")
  public int deleteAdminByUserId(@RequestParam("userId") long userId) {
    int result = adminMapper.deleteAdminByUserId(userId);
    if (result > 0) {
      System.out.println("删除管理员信息");
      return 1;
    } else {
      return 0;
    }
  }
}
